﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Should;
using UserStoryTrackerDemo.Data;
using UserStoryTrackerDemo.Domain.Core.Repository;
using UserStoryTrackerDemo.Domain.Pocos;

namespace UserStoryTrackerDemo.UnitTests.Data
{
	[TestClass]
	public class RepositoryTest
	{
		[TestMethod]
		public void GetUserStoriesFromRepository()
		{
			IRepository<UserStory> repo = new Repository<UserStory>(new List<UserStory>());
			repo.GetAll().Count.ShouldEqual(0);
			repo = new Repository<UserStory>(new List<UserStory>()
			                                 	{
			                                 		new UserStory()
			                                 			{
			                                 				Id = 1,
			                                 				AsA = "Developer",
			                                 				ICan = "test this page",
			                                 				SoThatBecause = "I can see it work",
			                                 				Completed = false,
			                                 			}
			                                 	});

			repo.GetAll().Count.ShouldEqual(1);
			
		}

		[TestMethod]
		public void GetUserStoriesFromRepositoryUsingDatabase()
		{
			IRepository<UserStory> repo = new Repository<UserStory>(Database.Instance.GetUserStoryData());
			repo.GetAll().Count.ShouldEqual(3);

		}

		[TestMethod]
		public void GetUserStoryByIdFromRepositoryUsingDatabase()
		{
			IRepository<UserStory> repo = new Repository<UserStory>(Database.Instance.GetUserStoryData());
			repo.GetById(1).Id.ShouldEqual(1);
			repo.GetById(1).AsA.ShouldEqual("user of the system");
		}

		[TestMethod]
		public void SaveUserStoryInRepositoryUsingDatabase()
		{
			var story = new UserStory()
			            	{AsA = "Unit Test", ICan = "save a user story", SoThatBecause = "I want to pass", Completed = false};

			IRepository<UserStory> repo = new Repository<UserStory>(Database.Instance.GetUserStoryData());
			repo.Save(story);
			repo.GetAll().Count.ShouldEqual(4);
		}
	}
}
